/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.deptBudget.db.impl;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.yunhoo.deptBudget.db.dao.FinBudgetAllotDao;
import com.yunhoo.deptBudget.model.Budget;
import com.yunhoo.sys.db.util.DbTool;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class FinBudgetAllotDaoImpl extends SqlMapDaoTemplate implements FinBudgetAllotDao {

    private static SqlMapClient sqlmap;
    private String nameSpace = "finBudgetAllot.";

    public FinBudgetAllotDaoImpl(DaoManager daoManager) {
        super(daoManager);
        sqlmap = sqlmap = DbTool.getSqlMapClient();
    }

    @Override
    public void deleteListById(List<Budget> paramli) throws SQLException {
        System.out.println(nameSpace + "deleteById");
        sqlmap.startBatch();
        for (Budget param : paramli) {
            sqlmap.delete(nameSpace + "deleteById", param);
        }
        sqlmap.executeBatch();
    }

    @Override
    public void updateListById(List<Budget> paramli) throws SQLException {
        System.out.println(nameSpace + "updateById * n");
        sqlmap.startBatch();
        for (Budget param : paramli) {
            sqlmap.update(nameSpace + "updateById", param);
        }
        sqlmap.executeBatch();
    }

    @Override
    public void saveList(List<Budget> paramli, Budget deleteParam) throws SQLException {
        System.out.println(nameSpace + "insert * n");
        sqlmap.startBatch();
        sqlmap.delete(nameSpace + "delete", deleteParam);
        for (Budget param : paramli) {
            sqlmap.insert(nameSpace + "insert", param);
        }
        sqlmap.executeBatch();
    }

    @Override
    public List<Budget> queryListAllFinProjAndBudget(Budget param) {
        try {
            System.out.println(nameSpace + "queryListAllFinProjAndBudget");
            return sqlmap.queryForList(nameSpace + "queryListAllFinProjAndBudget", param);
        } catch (SQLException ex) {
            Logger.getLogger(FinBudgetAllotDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public List<Budget> queryListAllDeptBudget(Budget param) {
        try {
            System.out.println(nameSpace + "queryListAllDeptBudget");
            return sqlmap.queryForList(nameSpace + "queryListAllDeptBudget", param);
        } catch (SQLException ex) {
            Logger.getLogger(FinBudgetAllotDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public List<Budget> queryListCurrentAndLastYearDeptBudget(Budget param) {
        try {
            System.out.println(nameSpace + "queryListCurrentAndLastYearDeptBudget");
            return sqlmap.queryForList(nameSpace + "queryListCurrentAndLastYearDeptBudget", param);
        } catch (SQLException ex) {
            Logger.getLogger(FinBudgetAllotDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
